/*******************************************************************************
 功能：
 　　用于快速设置及获取表单参数，并提交到指定页面，
     以替代使用隐藏表单保存参数的方法
      　　
********************************************************************************/

function FormMap(action,target){
  this.form = document.createElement("FORM");
  this.form.action = action;
  this.form.target = (target == undefined) ? "_self" : target;
  //添加键值
  this.put = function (key,value){
      var oAllInput = this.form.getElementsByTagName("INPUT");
      var isExist = false; //指定的键值是否存在
      var oInput;
      for (var i=0;i<oAllInput.length;i++){
        if (oAllInput[i].name == key){
          oInput = oAllInput[i];
          isExist = true;
          break;
        }
      }
      if (isExist){
        oInput.value = value;
      }else{
        oInput = document.createElement("INPUT");
        oInput.type = "hidden";
        oInput.name = key;
        oInput.value = value;
        this.form.insertAdjacentElement("beforeEnd",oInput);
      }
    }
   //获取键值
  this.get = function (key){
      var oInput = this.form.getElementsByTagName("INPUT");
      for (var i=0;i<oInput.length;i++){
        if (oInput[i].name == key){
          return oInput[i].value;
        }
      }
    }
  this.submit = function(){
      try {
        this.form.style.display = "none";
        document.body.insertAdjacentElement("beforeEnd",this.form);
      }catch (E){
        alert ("页面未完全载入，请稍后执行submit()");
        return;
      }      
      this.form.method = "POST";
      this.form.submit();
    }
}

/***************************************************************************************
 * 导出Excel和下载文件的Js类
 * Author:crazy_rain
 ***************************************************************************************/
/**
 * title 导出excel的文件名
 * htmlContent 要导出的excel的Table的内容
 * ctxPath 应用的上下文路径
 */

function doExcelExport(title,htmlContent,ctxPath){
	this.exportForm = new FormMap(ctxPath + "/common/ExportExcel.do");
	this.exportForm.put("exportFileName",title);
	this.exportForm.put("tableHTML",htmlContent);
	this.exportForm.submit();
}
/**
 * title 要下载的文件的全路径名
 * ctxPath 应用的上下文路径
 * isRelative 该文件路径是否是上下文相关
 */
function doDownloadFile(filePath,ctxPath,isRelative){
	this.downloadForm = new FormMap(ctxPath + "/common/DownloadFile.do","_blank");
	this.downloadForm.put("FILE_PATH",filePath);
	if(isRelative){
		this.downloadForm.put("IS_RELATIVE_PATH","true");
	}
	this.downloadForm.submit();
}
